import { _decorator, Component, Node, Prefab } from 'cc';
import { poolManager } from '../../../../Framework/Scripts/Managers/poolManager';
import { enemyBase } from '../enemyBase';
import { boss_aoeBomb } from '../enemySkill/boss_aoeBomb';
const { ccclass, property } = _decorator;


/** 
  周无邪出品
  本源码用于学习研究使用。
  作者联系方式：tuya7078（微信）。
 */
@ccclass('dragon')
export class dragon extends enemyBase {
    @property(Prefab)
    public fire: Prefab = null!;//武器预制体
    @property(Node)
    public ndRightHand: Node = null!;//右手节点

    private isA: boolean = false


    private atime: number = 5
    private nowTime: number = 0
    start() {

    }
    protected pursuit_building() {
        this.isA = false

        super.pursuit_building()

    }

    protected enemy_pursuit() {
        this.isA = false

        super.enemy_pursuit()
    }
    attack() {
        if (this.isA) {
            return
        }
        this.isA = true
        super.attack()
      //  this.NavTs.StopNav()
        this.node.lookAt(this.attackTarget.getWorldPosition())
        this.enemyModel.playAni(this.attackAni1, false,()=>{
            this.NavTs.StopNav()
            this.enemyModel.playAni(this.walkAni, true)
        })
    }
    onLoad(){
        super.onLoad()
    }
    attickCallback() {



        super.attickCallback()
        const n: Node = poolManager.instance.getNode(this.fire, this.ndRightHand)
        n.setScale(0.025,0.025,0.025)

        n.forward=this.node.forward

        const ts: boss_aoeBomb = n.getComponent(boss_aoeBomb)
        if (ts) {

            ts.init(this.node)
        }


    }//攻击回调

    update(dt: number) {
        
        if (this.isA&&this.attackTarget) {
            this.node.lookAt(this.attackTarget.getWorldPosition())
            this.nowTime += dt
            if (this.nowTime >= this.atime) {
                this.node.lookAt(this.attackTarget.getWorldPosition())
                this.nowTime = 0
                this.isA = false
            }
        }
        super.update(dt)

    }
}


